//
//  GOWebViewController.m
//  HuiKaoClient
//
//  Created by 龚 杰 on 13-2-27.
//  Copyright (c) 2013年 龚 杰. All rights reserved.
//

#import "GOWebViewController.h"

@interface GOWebViewController ()

@end

@implementation GOWebViewController
@synthesize WebURL = m_WebURL;
@synthesize HttpURL = m_HttpURL;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = YES;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor colorWithRed:240/255.f green:240/255.f blue:240/255.f alpha:1]];
    
    UIImageView* tTopView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
    [tTopView setImage:[UIImage imageNamed:@"browser_top.png"]];
    [self.view addSubview:tTopView];
    [tTopView release];
    
    UIButton* tBackBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [tBackBtt setImage:[UIImage imageNamed:@"browser_back.png"] forState:UIControlStateNormal];
    tBackBtt.frame =CGRectMake(15, 12, 23, 20);
    [tBackBtt addTarget:self action:@selector(changePop) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:tBackBtt];
    
    UIView* tFootView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-44, 320,44)];
    [tFootView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"browser_bottom.png"]]];
    
    m_NextBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [m_NextBtt setImage:[UIImage imageNamed:@"browser_left.png"] forState:UIControlStateNormal];
    m_NextBtt.frame =CGRectMake(20, 12, 23, 23);
    [m_NextBtt addTarget:self action:@selector(changeNext) forControlEvents:UIControlEventTouchUpInside];
    [tFootView addSubview:m_NextBtt];
    
    m_GOBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [m_GOBtt setImage:[UIImage imageNamed:@"browser_right.png"] forState:UIControlStateNormal];
    m_GOBtt.frame =CGRectMake(90, 12, 23, 23);
    [m_GOBtt addTarget:self action:@selector(changeBack) forControlEvents:UIControlEventTouchUpInside];
    [tFootView addSubview:m_GOBtt];
    
    m_RTBtt = [UIButton buttonWithType:UIButtonTypeCustom];
    [m_RTBtt setImage:[UIImage imageNamed:@"browser_refresh.png"] forState:UIControlStateNormal];
    m_RTBtt.frame =CGRectMake(260, 12, 23, 23);
    [m_RTBtt addTarget:self action:@selector(changeRefresh) forControlEvents:UIControlEventTouchUpInside];
    [tFootView addSubview:m_RTBtt];
    
    
    [self.view addSubview:tFootView];
    [tFootView release];
    

    
    m_COWebView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 44, 320, self.view.frame.size.height-44-44)];
    [m_COWebView setBackgroundColor:[UIColor colorWithRed:240/255.f green:240/255.f blue:240/255.f alpha:1]];
    m_COWebView.delegate = self;
    [self.view addSubview:m_COWebView];
    if (m_WebURL.length > 0) {
        [m_COWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:m_WebURL]]];
    }else{
        
    }
    if (m_COWebView.canGoBack) {
        [m_NextBtt setImage:[UIImage imageNamed:@"browser_left.png"] forState:UIControlStateNormal];
    }else{
        [m_NextBtt setImage:[UIImage imageNamed:@"browser_left_dark.png"] forState:UIControlStateNormal];
    }
    if (m_COWebView.canGoForward) {
        [m_GOBtt setImage:[UIImage imageNamed:@"browser_right.png"] forState:UIControlStateNormal];
    }else{
        [m_GOBtt setImage:[UIImage imageNamed:@"browser_right_dark.png"] forState:UIControlStateNormal];
    }
}
- (void)changePop
{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)changeNext
{
    [m_COWebView goBack];
}
- (void)changeBack
{
    [m_COWebView goForward];
}
- (void)changeRefresh
{
    [m_COWebView reload];
}

#pragma mark UIWebViewDelegate
- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"1111");
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{

    if (m_COWebView.canGoBack) {
        [m_NextBtt setImage:[UIImage imageNamed:@"browser_left.png"] forState:UIControlStateNormal];
    }else{
        [m_NextBtt setImage:[UIImage imageNamed:@"browser_left_dark.png"] forState:UIControlStateNormal];
    }
    if (m_COWebView.canGoForward) {
        [m_GOBtt setImage:[UIImage imageNamed:@"browser_right.png"] forState:UIControlStateNormal];
    }else{
        [m_GOBtt setImage:[UIImage imageNamed:@"browser_right_dark.png"] forState:UIControlStateNormal];
    }

}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"33333");
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc
{
    [m_WebURL release];
    [m_HttpURL release];
    [m_COWebView release];
    m_NextBtt = nil;
    m_GOBtt = nil;
    m_RTBtt = nil;
    [super dealloc];
}
@end
